import axios from "axios";
const request = axios.create({
    baseURL:"/api",
    timeout:5000
})

//拦截器
request.interceptors.request.use(request=>{//每次axios请求发起之前执行
    let token = localStorage.getItem("token");
    request.headers.Authorization = token?token:null;
    // console.log("准备发起请求：" + request.url)
    return request;
}, err=>{
    return Promise.reject(err);
})
request.interceptors.response.use(response=>{//每次axios得到响应后执行
    if(response.data.code == 402){
        localStorage.removeItem("token");
        window.location.reload();
    }
    return response;
}, err=>{
    return Promise.reject(err);
})

export default request;